//============================================================================
// Name        : file_headder_data.cpp
// Author      : bt
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
typedef struct
{
	char*name;
	int y;
	int dong,cot;
}headder;
typedef struct
{
	int x;
}matran;


int main()
{
	int a[20][20];
	int i,j;
	FILE*f;
	matran mt;
	headder h;
	int n,m;
	printf("nhap n: ");
	scanf("%d",&n);
	printf("nhap m: ");
	scanf("%d",&m);
	h.name="duong";
	h.dong=n;
	h.cot =m;
	h.y = 50;
	f = fopen("file","w");
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		{
			printf("a[%d][%d]: ",i,j);
			scanf("%d",&a[i][j]);
			mt.x=a[i][j];
			fwrite(&mt,sizeof(matran),1,f);
		}
	}
	fclose(f);
	//read it
	f=fopen("file","r");

	 for (i=1;i<=n; i++)
	 {
		 for(j=1;j<=m;j++)
		 {
			 fread(&mt,sizeof(matran),1,f);
			 printf(" %d",mt.x);
		 }
		 printf("\n");
	 }
	 fclose(f);
	//information
	 printf("**************thong tin**************: \n");
	 printf("ten: %s\n",h.name);
	 printf("tuoi: %d\n",h.y);
	 printf("so dong: %d\n",h.dong);
	 printf("so cot: %d\n",h.cot);

	 printf("\n");
	return 0;
}
